#include <iostream>

int BinarySearch(int* an_array, int key, int first, int last);

int main() {
	using namespace std;
	int n_array[] = {3,6,9,14,23,25,29,35,39,48,49,58,61,62,74,79,89,92,105};
	int size = sizeof(n_array)/sizeof(n_array[0]);
	BinarySearch(n_array,105,0,size);


	//system("PAUSE");
	return 0;
}

	int BinarySearch(int * an_array, int key, int first, int last) {
		using namespace std;
		int mid;
		mid = (first + last) /2;
		if ( key == an_array[mid]) {
			cout << " The element is at position " << mid << endl;
			return 0;
		}
		if ( key > an_array[mid]) {
			first= mid + 1;
			BinarySearch(an_array,key,first,last); // recursion 
		}
		if ( key < an_array[mid]) {
			last= mid - 1;
			BinarySearch(an_array,key,first,last);
		}

	}
			
